<?php

if(!isset($limit)) {
    $limit=5;
}

if(!isset($criteria)) {
    $criteria = array(
        'class' => 'Team',
        'field' => 'iValue',
        'name' => 'Tv',
        'direction' => 'desc');
}

$teams = $this->requestAction('teams/index/sort:'.$criteria['class'].'.'.$criteria['field'].'/direction:'.$criteria['direction'].'/limit:'.$limit);

if(!isset($noRace))
    $noRace = false;
if(!isset($noCoach))
    $noCoach = false;

?>
<div id="elt_best_teams" id="best">
    <h3><?php echo $title;?></h3>
    <?php if (!empty($teams)):?>
    <table cellpadding = "0" cellspacing = "0">
    <tr>
        <th><?php __('Name');?></th>
        <?php if(!$noCoach) {?><th><?php __('Coach');?></th><?php }?>
        <?php if(!$noRace) {?><th><?php __('Race');?></th><?php }?>
        <th><?php __($criteria['name']);?></th>
    </tr>
    <?php
        $i = 0;
        foreach ($teams as $team):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
        ?>
        <tr<?php echo $class;?>>
            <td><?php echo $html->link($team['Team']['strName'], array('controller' => 'teams', 'action' => 'view', $team['Team']['id'])); ?></td>
            <?php if(!$noCoach) {?><td><?php echo $html->link($team['Coach']['strName'], array('controller' => 'coaches', 'action' => 'view', $team['Team']['coach_id'])); ?></td><?php }?>
            <?php if(!$noRace) {?><td><?php echo $html->link($team['Race']['LocalizedString'][$locale], array('controller' => 'races', 'action' => 'view', $team['Team']['race_id'])); ?></td><?php }?>
            <td><?php echo $team[$criteria['class']][$criteria['field']];?></td>
        </tr>
    <?php endforeach; ?>
    </table>
<?php endif; ?>
</div>